
<template>
  <div>
    <el-dialog title="更改密码" :visible.sync="passwordVisible" :before-close="close" width="600px">
      <el-form label-width="100px">
        <el-form-item label="用户名">
          <el-input v-model="userModel.userName" :disabled="true" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="新密码">
          <el-input type="password" v-model="editPassWords.password" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="确认新密码">
          <el-input type="password" v-model="editPassWords.confirmpassword" auto-complete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleEditPassWord">提 交</el-button>
        <el-button @click="close">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  props: ["passwordVisible", "userModel"], //接受父组件的值
  data() {
    return {
      editPassWords: {
        userid: "",
        password: "",
        confirmpassword: ""
      },
      formLabelWidth: "120px"
    };
  },

  methods: {
    close() {
      this.editPassWords.password = "";
      this.editPassWords.confirmpassword = "";
      this.$emit("closePassword");
    },

    handleEditPassWord() {
      this.editPassWords.userid = this.userModel.id;
      this.$api
        .post("/api/User/updatePassword", this.editPassWords)
        .then(rsp => {
          if (rsp != false) {
            this.close();
          }
        });
    }
  }
};
</script>

